<template><div><h2 id="数据表格" tabindex="-1"><a class="header-anchor" href="#数据表格"><span>数据表格</span></a></h2>
<p>Dcat Admin 中文文档 /</p>
<h2 id="数据表格动作" tabindex="-1"><a class="header-anchor" href="#数据表格动作"><span>数据表格动作</span></a></h2>
<h2 id="表格动作基类-gridaction" tabindex="-1"><a class="header-anchor" href="#表格动作基类-gridaction"><span>表格动作基类 (GridAction)</span></a></h2>
<p>所有数据表格相关的动作类，包括<a href="https://learnku.com/docs/dcat-admin/1.x/toolbar/8093" target="_blank" rel="noopener noreferrer">工具栏按钮</a>(<code v-pre>AbstractTool</code>)、<br>
<a href="https://learnku.com/docs/dcat-admin/1.x/use-and-extension-of-rows/8092" target="_blank" rel="noopener noreferrer">行操作</a>(<code v-pre>RowAction</code>)、<a href="https://learnku.com/docs/dcat-admin/1.x/toolbar/8093#batch" target="_blank" rel="noopener noreferrer">批量操作</a>(<code v-pre>BatchAction</code>)<br>
等等操作按钮的基类都继承自<code v-pre>Dcat\Admin\Grid\GridAction</code>类，而<code v-pre>GridAction</code>则继承自<a href="https://learnku.com/docs/dcat-admin/1.x/basic-use/8124" target="_blank" rel="noopener noreferrer">动作类基类</a>(<code v-pre>Action</code>)。</p>
<p>下面将介绍<code v-pre>GridAction</code>类中增加的方法或属性</p>
<h3 id="表格实例-parent" tabindex="-1"><a class="header-anchor" href="#表格实例-parent"><span>表格实例 (parent)</span></a></h3>
<p>通过 <code v-pre>parent</code> 属性可以获取到表格实例 (<code v-pre>Dcat\Admin\Grid</code>)。</p>
<p>下面简单的演示下用法，这段代码没有任何实际意义</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>GridAction</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyAction</span> <span class="token keyword">extends</span> <span class="token class-name">GridAction</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">html</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$gridName</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">parent</span><span class="token operator">-></span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token operator">...</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="表格页面地址-resource" tabindex="-1"><a class="header-anchor" href="#表格页面地址-resource"><span>表格页面地址 (resource)</span></a></h3>
<p>通过 <code v-pre>resource</code> 方法可以获取到表格页面的地址。</p>
<p>下面简单的演示下用法，这段代码没有任何实际意义</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>GridAction</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyAction</span> <span class="token keyword">extends</span> <span class="token class-name">GridAction</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">html</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token comment">// 假如你的列表页路径为 /admin/users，则这里的值为 http://域名/admin/users    </span></span>
<span class="line">        <span class="token variable">$path</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">resource</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token operator">...</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="工具栏操作按钮基类-abstracttool" tabindex="-1"><a class="header-anchor" href="#工具栏操作按钮基类-abstracttool"><span>工具栏操作按钮基类 (AbstractTool)</span></a></h2>
<p>表格工具栏按钮基类(<code v-pre>Dcat\Admin\Grid\Tools\AbstractTool</code>)继承自<code v-pre>GridAction</code>类。</p>
<p>下面将介绍<code v-pre>AbstractTool</code>类中增加的方法或属性</p>
<h3 id="按钮样式-style" tabindex="-1"><a class="header-anchor" href="#按钮样式-style"><span>按钮样式 (style)</span></a></h3>
<p>通过 <code v-pre>style</code> 属性可以设置工具栏按钮的类(<code v-pre>class</code>)，默认值为 <code v-pre>btn btn-white waves-effect</code>。</p>
<p>下面简单的演示下用法</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>AbstractTool</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyTool</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractTool</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token variable">$style</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'btn btn-outline-primary waves-effect'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="批量操作基类-batchaction" tabindex="-1"><a class="header-anchor" href="#批量操作基类-batchaction"><span>批量操作基类 (BatchAction)</span></a></h2>
<p>表格工具栏按钮基类(<code v-pre>Dcat\Admin\Grid\Tools\BatchAction</code>)继承自<code v-pre>GridAction</code>类。</p>
<p>下面将介绍<code v-pre>BatchAction</code>类中增加的方法或属性</p>
<h3 id="获取选中行的主键数组-getselectedkeysscript" tabindex="-1"><a class="header-anchor" href="#获取选中行的主键数组-getselectedkeysscript"><span>获取选中行的主键数组 (getSelectedKeysScript)</span></a></h3>
<p>通过 <code v-pre>getSelectedKeysScript</code> 方法可以生成获取选中的行的主键数组的<code v-pre>JS</code>代码。</p>
<p>下面简单的演示下用法</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>BatchAction</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyBatchAction</span> <span class="token keyword">extends</span> <span class="token class-name">BatchAction</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * <span class="token punctuation">{</span><span class="token keyword">@inheritdoc</span><span class="token punctuation">}</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">actionScript</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$warning</span> <span class="token operator">=</span> <span class="token function">__</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'No data selected!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token string heredoc-string"><span class="token delimiter symbol"><span class="token punctuation">&lt;&lt;&lt;</span>JS</span></span>
<span class="line">    var key = <span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token function">getSelectedKeysScript</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span></span>
<span class="line"></span>
<span class="line">    if (key.length === 0) {</span>
<span class="line">        Dcat.warning('<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$warning</span><span class="token punctuation">}</span></span>');</span>
<span class="line">        return ;</span>
<span class="line">    }</span>
<span class="line">    Object.assign(data, {_key:key});</span>
<span class="line"><span class="token delimiter symbol">JS<span class="token punctuation">;</span></span></span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="行操作基类-rowaction" tabindex="-1"><a class="header-anchor" href="#行操作基类-rowaction"><span>行操作基类 (RowAction)</span></a></h2>
<p>表格工具栏按钮基类(<code v-pre>Dcat\Admin\Grid\Tools\RowAction</code>)继承自<code v-pre>GridAction</code>类。</p>
<p>下面将介绍<code v-pre>RowAction</code>类中增加的方法或属性</p>
<h3 id="行数据-row" tabindex="-1"><a class="header-anchor" href="#行数据-row"><span>行数据 (row)</span></a></h3>
<p>通过 <code v-pre>row</code> 属性可以获取到当前行数据内容。</p>
<p>下面简单的演示下用法，这段代码没有任何实际意义</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>RowAction</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyRowAction</span> <span class="token keyword">extends</span> <span class="token class-name">RowAction</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">html</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token comment">// 获取当前行的字段值</span></span>
<span class="line">        <span class="token variable">$username</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">row</span><span class="token operator">-></span><span class="token property">username</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token comment">// 转化为数组</span></span>
<span class="line">        <span class="token variable">$rowArray</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">row</span><span class="token operator">-></span><span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token operator">...</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="主键值-getkey" tabindex="-1"><a class="header-anchor" href="#主键值-getkey"><span>主键值 (getKey)</span></a></h3>
<p>通过 <code v-pre>getKey</code> 属性方法可以获取到当前行数据的主键值(<code v-pre>ID</code>)。</p>
<p>下面简单的演示下用法，这段代码没有任何实际意义</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>RowAction</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyRowAction</span> <span class="token keyword">extends</span> <span class="token class-name">RowAction</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">html</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$id</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">getKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token operator">...</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div></template>


